﻿using DevExpress.XtraLayout;
using System.Windows.Forms;

namespace Inaction.UI.Extensions.ControlExtensions
{
    public static class LayoutControlExtender
    {
        public static void Extend(Control c, Form form)
        {
            if (!(c is LayoutControl)) return;
            var layoutControl = c as LayoutControl;
            layoutControl.AllowCustomizationMenu = true;
            layoutControl.OptionsCustomizationForm.ShowPropertyGrid = Inaction.Security.Principal.Instance.Identity.IsAdmin;
            layoutControl.OptionsCustomizationForm.ShowLoadButton = false;
            layoutControl.OptionsCustomizationForm.ShowSaveButton = false;
            layoutControl.Margin = new Padding(0);
            SetLayoutControl(layoutControl.Items);
        }
        private static void SetLayoutControl(DevExpress.XtraLayout.Utils.BaseItemCollection items)
        {
            if (items == null) return;
            foreach (BaseLayoutItem item in items)
            {
                if (item is LayoutControlGroup)
                {
                    var group = item as LayoutControlGroup;
                    group.Padding = new DevExpress.XtraLayout.Utils.Padding(0);
                    group.Spacing = new DevExpress.XtraLayout.Utils.Padding(0);
                    SetLayoutControl(group.Items);
                }
                if (item is TabbedGroup)
                {
                    var tabbedGroup = item as TabbedGroup;
                    tabbedGroup.Padding = new DevExpress.XtraLayout.Utils.Padding(0);
                    tabbedGroup.Spacing = new DevExpress.XtraLayout.Utils.Padding(0);
                }
                if (item is LayoutItem)
                {
                }
            }
        }
    }
}